package com.mdb.open.trade.resource.trade;

/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfInwardRemittanceService.java
* Author:   you.yichao
* Date:     2019-07-02
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-07-02          V1.00        代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.enums.OrderByEnum;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.trade.constant.trade.Fields;
import com.mdb.open.trade.domain.bo.trade.QueryInwardRemittancePageListBo;
import com.mdb.open.trade.domain.dto.trade.QueryInwardRemittancePageListDto;
import com.mdb.open.trade.domain.po.trade.InwardRemittance;
import com.mdb.open.trade.domain.vo.trade.InwardRemittanceVo;
import com.mdb.open.trade.service.trade.TfInwardRemittanceService;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 类描述：
 *  汇入表 前端控制器
 *
 * @author you.yichao
 * @date 2019-07-02
 */
@Log4j2
@RestController
@RequestMapping("tf/inward")
@Api(tags = "贸易金融资金汇入")
public class InwardRemittanceResource extends SuperResources {

    @Autowired
    TfInwardRemittanceService tfInwardRemittanceService;

    @Autowired
    LoginUserInfoHelper loginUserInfoHelper;

    @LogAnnotation
    @ApiOperation("汇入表列表 - 分页查询")
    @GetMapping("/page_list")
    public ListResultEx<InwardRemittanceVo> findByCondition(@ModelAttribute QueryInwardRemittancePageListDto dto) {

        //分页查询
        QueryInwardRemittancePageListBo bo = new QueryInwardRemittancePageListBo();
        bo.setStartDate(dto.getStartDate());
        bo.setEndDate(dto.getEndDate());
        bo.setReceiveAcc(dto.getReceiveAcc());
        bo.setRemitAcc(dto.getRemitAcc());
        bo.setStatus(dto.getStatus());
        bo.setPageNo(dto.getPageNo());
        bo.setPageSize(dto.getPageSize());
        bo.setSort(dto.getSort());
        bo.setOrder(dto.getOrder());
        bo.setCustomerCode(loginUserInfoHelper.getCustomerCode(true));

        if (ObjectUtil.isEmpty(dto.getSort())) {
            bo.setSort(Fields.ID);
            bo.setOrder(OrderByEnum.DESC);
        }

        IPage<InwardRemittance> page = tfInwardRemittanceService.pageQuery(bo);

        return this.convertListResult(page, remit -> {
            InwardRemittanceVo vo = new InwardRemittanceVo();
            vo.setCustomerCode(remit.getCustomerCode());
            vo.setCustomerName(remit.getCustomerName());
            vo.setMerchantNo(remit.getMerchantNo());
            vo.setMerchantName(remit.getMerchantName());
            vo.setRemitNo(remit.getRemitNo());
            vo.setBankInwardNo(remit.getBankInwardNo());
            vo.setReceiveAcc(remit.getReceiveAcc());
            vo.setRemitAcc(remit.getRemitAcc());
            vo.setRemitBank(remit.getRemitBank());
            vo.setRemitDate(remit.getRemitDate());
            vo.setRemitAmount(remit.getRemitAmount());
            vo.setCcy(remit.getCcy());
            vo.setPurposes(remit.getPurposes());
            vo.setChargeBearer(remit.getChargeBearer());
            vo.setDetails(remit.getDetails());
            vo.setClaimDate(remit.getClaimDate());
            vo.setStatus(remit.getStatus());
            vo.setRemark(remit.getRemark());
            vo.setCreateTime(remit.getCreateTime());
            vo.setUpdateTime(remit.getUpdateTime());
            return vo;
        });
    }

}
